import 'package:flutter/material.dart';
import 'package:flutter_list_view/flutter_list_view.dart';
import 'router/learn_router_page.dart';
import 'model/title_subtitle_model.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page')
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<TitleSubTitleModel> _dataList = [TitleSubTitleModel("路由","路由的基本和进阶用法")];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: FlutterListView(
          delegate: FlutterListViewDelegate(
                (BuildContext context, int index) {
                  TitleSubTitleModel model = _dataList[index];
                  return ListTile(
                      title: Text(model.title),subtitle: Text(model.subTitle),
                      onTap: (){
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => const LearnRouterPage()),
                        );
                      });
                },
            childCount: _dataList.length,
          )), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
